<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="岗位分类" prop="typeName">
        <el-cascader v-model="stationArr" :options="companyStationTypeList" :show-all-levels="false" :props="cascaderProps"
            @change="handleChangeFilterStation"></el-cascader>
      </el-form-item>
      <el-form-item label="岗位名称" prop="stationName">
        <el-input v-model="queryParams.stationName" placeholder="请输入岗位名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item v-if="!isCompany" label="所属单位" prop="compId">
        <el-select v-model="queryParams.compId" placeholder="请选择所属单位">
          <el-option v-for="item in companyList" :key="item.id" :label="item.compName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="岗位学历" prop="stationEdu">
        <el-select v-model="queryParams.stationEdu" placeholder="请选择岗位学历">
          <el-option label="全部" value=""></el-option>
          <el-option v-for="(item, index) in stationEduList" :key="index" :label="item" :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="岗位经验" prop="stationLesson">
        <el-select v-model="queryParams.stationLesson" placeholder="请选择岗位经验">
          <el-option label="全部" value=""></el-option>
          <el-option v-for="(item, index) in workExperienceList" :key="index" :label="item" :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工作地点" prop="stationAddr">
        <el-select v-model="queryParams.stationAddr" placeholder="请选择工作地点">
          <el-option label="全部" value=""></el-option>
          <el-option v-for="(item, index) in workPlaceList" :key="index" :label="item" :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="isExamine">
        <el-select v-model="queryParams.isExamine" placeholder="请选择工作地点">
          <el-option label="全部" value=""></el-option>
          <el-option v-for="(item, index) in examineList" :key="index" :label="item.label"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:station:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:station:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['system:station:export']">批量导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:station:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5" v-if="!isCompany">
        共计有: {{ statistics.compNum || 0 }}个单位, {{ statistics.stationNum || 0 }}个岗位, 浏览次数{{ statistics.pageviews || 0 }},
        {{ statistics.handNum || 0 }}人投递, {{ statistics.area }}
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 企业端 -->
    <el-table v-if="isCompany" v-loading="loading" :data="stationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="岗位名称" align="center" prop="stationName" />
      <el-table-column label="岗位分类" align="center" prop="typeName" />
      <el-table-column label="已关注/收到简历/浏览次数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.followVolume || 0 }}/{{ scope.row.handVolume || 0 }}/{{ scope.row.stationPageviews || 0
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学历要求" align="center" prop="stationEdu" />
      <el-table-column label="工作经验" align="center" prop="stationLesson" />
      <el-table-column label="薪资" align="center" prop="salaryRange" />
      <!-- <el-table-column label="参与招聘会" align="center" prop="" /> -->
      <el-table-column label="岗位状态" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <span v-if="scope.row.isExamine === 0" style="color: #E6A23C;">待审核</span>
          <span v-if="scope.row.isExamine === 1" style="color: #67C23A;">通过</span>
          <span v-if="scope.row.isExamine === 2" style="color: #F56C6C">未通过</span>
        </template>
      </el-table-column>

      <el-table-column label="上下架" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.statusBool" @change="handleChangeStatus(scope.row)">
          </el-switch>
        </template>
      </el-table-column>


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <!-- 0 未审核 1. 通过 2.未通过 -->
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:station:edit']">编辑</el-button>
          <el-button size="mini" type="text" @click="handleUpdate(scope.row, 'detail')"
            v-hasPermi="['system:station:edit']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 管理端 -->
    <el-table v-else v-loading="loading" :data="stationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="岗位分类" align="center" prop="typeName" />
      <el-table-column label="岗位名称" align="center" prop="stationName" />
      <el-table-column label="发布单位" align="center" prop="companyInfo.compName" />
      <el-table-column label="招聘人数" align="center" prop="recruitsNumber" />
      <el-table-column label="浏览次数" align="center" prop="stationPageviews" />
      <el-table-column label="投递简历" align="center" prop="handVolume" />
      <el-table-column label="推荐" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.hotBool" @change="handleChangeIsHot(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="上下架" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.statusBool" @change="handleChangeStatus(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <span v-if="scope.row.isExamine === 0" style="color: #E6A23C;">待审核</span>
          <span v-if="scope.row.isExamine === 1" style="color: #67C23A;">通过</span>
          <span v-if="scope.row.isExamine === 2" style="color: #F56C6C">未通过</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <!-- 0 未审核 1. 通过 2.未通过 -->
        <template slot-scope="scope">
          <el-button v-if="scope.row.isExamine === 0 || scope.row.isExamine === 2" size="mini" type="text"
            @click="handleUpdate(scope.row, 'examine')" v-hasPermi="['system:station:edit']">审批</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:station:edit']">编辑</el-button>
          <el-button size="mini" type="text" @click="handleUpdate(scope.row, 'detail')"
            v-hasPermi="['system:station:edit']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 经纬度 -->
    <el-dialog title="获取经纬度" :visible.sync="openDialog" append-to-body width="80%">
      <iframe :src="'https://lbs.qq.com/getPoint/'" width="100%" height="750px" frameBorder="0"></iframe>
    </el-dialog>

    <!-- 添加或修改公司岗位信息对话框 -->
    <el-dialog class="station-form" :title="title" v-if="open" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属单位" prop="compId" v-if="!isCompany">
          <el-select v-model="form.compId" placeholder="请选择所属单位">
            <el-option v-for="item in companyList" :key="item.id" :label="item.compName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item label="岗位分类" prop="stationType">
          <el-cascader v-model="stationArr" :options="companyStationTypeList" :show-all-levels="false" :props="cascaderProps"
            @change="handleChangeStation"></el-cascader>
        </el-form-item>

        <el-form-item label="岗位名称" prop="stationName">
          <el-input v-model="form.stationName" placeholder="请输入岗位名称" />
        </el-form-item>

        <el-form-item label="招聘人数" prop="recruitsNumber">
          <el-input v-model="form.recruitsNumber" placeholder="请输入招聘人数" />
        </el-form-item>
        <el-form-item class="is-required salaryRange" label="薪资范围" prop="salaryRange">
          <el-form-item>
            <el-input-number v-model="startSalaryRange" :min="null" :controls="false"
              style="width: 120px;"></el-input-number>
          </el-form-item>
          <span style="margin: 0 10px">至</span>
          <el-form-item>
            <el-input-number :min="startSalaryRange" v-model="endSalaryRange" :controls="false"
              style="width: 120px;"></el-input-number>
          </el-form-item>
        </el-form-item>
        <el-form-item class="is-required" label="岗位描述" prop="stationSpec">
          <div class="desc-item" style="display: flex;" v-for="(item, index) in stationDescList" :key="index">
            <el-input v-model="item.value" style="width: 120px; display: block;margin-bottom: 10px;" />
            <div class="salary-btns">
              <i class="el-icon-circle-plus-outline" style="font-size: 22px;margin-left: 10px;"
                @click="handleAddDesc"></i>
              <i v-if="index > 0" class="el-icon-remove-outline" style="font-size: 22px;margin-left: 10px;"
                @click="handleReduce(index)"></i>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="岗位学历" prop="stationEdu">
          <el-select v-model="form.stationEdu" placeholder="请选择岗位学历">
            <el-option v-for="(item, index) in stationEduList" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岗位经验" prop="stationLesson">
          <el-select v-model="form.stationLesson" placeholder="请选择岗位经验">
            <el-option v-for="(item, index) in workExperienceList" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工作地址" class="is-required" prop="workAddr">
          <template>
            <el-radio-group v-model="wrokPlaceType" @change="handleChangePlace">
              <el-radio :label="1">使用公司地址</el-radio>
              <el-radio :label="2">使用其他地址</el-radio>
            </el-radio-group>
          </template>
          <el-select v-if="wrokPlaceType === 2" v-model="form.stationAddr" placeholder="请选择工作地点">
            <el-option v-for="(item, index) in workPlaceList" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="经纬度" class="is-required" v-if="wrokPlaceType === 2" prop="longitudeAndLatitude">
          <el-input v-model.trim="longitudeAndLatitude" placeholder="请输入经纬度" />
          <el-button class="mt10" type="primary" @click="openDialog = true">选择经纬度</el-button>
        </el-form-item>

        <el-form-item label="岗位详情" prop="stationDesc">
          <editor v-model="form.stationDesc" :min-height="192" />
        </el-form-item>

        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>

        <!-- <el-form-item label="微信号" prop="wxnumber">
          <el-input v-model="form.wxnumber" placeholder="请输入微信号" />
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer" v-if="dialogType === 'examine'">
        <el-button type="primary" @click="handlePass(1)">审核通过</el-button>
        <el-button @click="handlePass(2)">审核不通过</el-button>
      </div>
      <div slot="footer" class="dialog-footer" v-else-if="dialogType !== 'detail'">
        <el-button type="primary" @click="submitForm">{{ isCompany ? '提交审核' : '确 定' }}</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 岗位导入对话框 -->
    <el-dialog title="批量导入招聘岗位" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
        :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { getHireDicts } from '@/api/system/dict/data'
import { listCompany } from "@/api/system/company";
import { listStation, getStation, delStation, addStation, updateStation, stationCount, stationTree } from "@/api/system/station";
const examineList = [{
  label: '待审核',
  value: 0
}, {
  label: '通过',
  value: 1
}, {
  label: '未通过',
  value: 2
}]
export default {
  name: "Station",
  data() {
    var validateSalaryRange = (rule, value, callback) => {
      if (!this.startSalaryRange || !this.endSalaryRange) {
        callback(new Error('请输入薪资范围'))
      } else {
        callback();
      }
    }
    var validateLongitude = (rule, value, callback) => {
      if (this.wrokPlaceType === 2) {
        if (!this.longitudeAndLatitude) {
          callback(new Error('请选择经纬度'))
        } else {
          callback();
        }
      } else {
        callback();
      }
    }
    var validateWorkAddr = (rule, value, callback) => {
      if (this.wrokPlaceType === 2) {
        if (!this.form.stationAddr) {
          callback(new Error('请选择经工作地点'))
        } else {
          callback();
        }
      } else {
        callback();
      }
    }
    var validateStationSpec = (rule, value, callback) => {
      const isEmpty = this.stationDescList.some(item => item.value === '')
      if (isEmpty) {
        callback(new Error('请输入岗位描述'))
      } else {
        callback();
      }
    }
    // validateStationSpec
    return {
      // 遮罩层
      examineList,
      loading: true,
      openDialog: false,
      longitudeAndLatitude: '',
      startSalaryRange: null,
      endSalaryRange: null,
      wrokPlaceType: 1,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公司岗位信息表格数据
      stationList: [],
      stationDescList: [{
        value: ''
      }], // 岗位描述
      upload: {
        // 是否显示弹出层
        open: false,
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/station/import"
      },

      // 弹出层标题
      title: "",
      dialogType: '',
      companyStationTypeList: [],
      cascaderProps: {
        label: 'typeName',
        value: 'id'
      },
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        compId: null,
        stationType: null,
        stationAddr: null,
        stationEdu: null,
        stationLesson: null,
        recruitsNumber: null,
        salaryRange: null,
        stationSpecifics: null,
        stationDesc: null,
        phone: null,
        status: null
      },
      // 表单参数
      form: {},
      statistics: {},
      // 表单校验
      rules: {
        compId: [
          { required: true, message: "单位名称不能为空", trigger: "blur" },
        ],
        stationType: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" },
        ],
        recruitsNumber: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" },
        ],
        stationEdu: [
          { required: true, message: "岗位学历不能为空", trigger: "blur" },
        ],
        stationLesson: [
          { required: true, message: "岗位经验不能为空", trigger: "blur" },
        ],
        stationDesc: [
          { required: true, message: "岗位详情不能为空", trigger: "blur" },
        ],
        salaryRange: [
          { validator: validateSalaryRange, trigger: ['change', 'blur'] }
        ],
        endSalaryRange: [
          { required: true, message: "岗位薪酬截止不能为空", trigger: "blur" },
        ],
        longitudeAndLatitude: [
          { validator: validateLongitude, trigger: ['change', 'blur'] }
        ],
        workAddr: [
          { validator: validateWorkAddr, trigger: ['change', 'blur'] }
        ],
        stationSpec: [
          { validator: validateStationSpec, trigger: ['change', 'blur'] }
        ],
        // stationSpec
      },
      companyList: [],
      stationEduList: [],
      workExperienceList: [],
      workPlaceList: []
    };
  },
  computed: {
    isCompany() {
      return this.$store.state.user.roles[0] === 'company' && !!this.$store.state.user.userData.compId
    },
    companyId() {
      return this.$store.state.user.userData.compId
    }
  },
  created() {
    this.getList();
    this.getStationList();
    this.getHireDicts();
    this.getStationCount();
    this.getCompanyList()
  },
  methods: {
    /** 查询公司岗位信息列表 */
    getList() {
      this.loading = true;
      listStation(this.queryParams).then(response => {
        this.stationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询公司类型管理列表 */
    getStationList() {
      stationTree(this.queryParams).then(response => {
        this.companyStationTypeList = this.removeThirdLevelChildren(response.data)
      });
    },
    removeThirdLevelChildren(treeData) {
      if (!treeData.length) return 
      function processNode(node, currentLevel) {
        if (currentLevel === 2) { // 第三层节点（从0开始计数）
          if ('children' in node) {
            delete node.children; // 强制删除children属性
          }
        } else if (node.children && node.children.length > 0) {
          // 递归处理子节点并增加层级
          node.children.forEach(child =>
            processNode(child, currentLevel + 1)
          );
        }
      }

      // 遍历根节点
      treeData.forEach(rootNode => {
        processNode(rootNode, 0); // 根节点从第0层开始
      });

      return treeData;
    },
    /** 查询招聘公司信息列表 */
    getCompanyList() {
      this.loading = true;
      listCompany({ pageNum: 1, pageSize: 999 }).then(response => {
        this.companyList = response.rows;
      });
    },
    // 获取字典
    getHireDicts() {
      getHireDicts().then(res => {
        this.stationEduList = res.data.filter(item => item.field === 'stationEdu')[0].dicts
        this.workExperienceList = res.data.filter(item => item.field === 'stationLesson')[0].dicts
        this.workPlaceList = res.data.filter(item => item.field === 'stationAddr')[0].dicts
      })
    },
    // 统计数据
    getStationCount() {
      stationCount().then(res => {
        console.log(res)
        this.statistics = res.data
      })
    },
    // 新增描述
    handleAddDesc() {
      this.stationDescList.push({ value: '' })
    },
    handleReduce(index) {
      this.stationDescList.splice(index, 1)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        compId: null,
        typeName: null,
        stationType: null,
        stationAddr: null,
        stationEdu: null,
        stationLesson: null,
        recruitsNumber: null,
        salaryRange: null,
        stationSpecifics: null,
        stationDesc: null,
        phone: null,
        status: null,
        compName: null,
        startSalaryRange: null,
        endSalaryRange: null,
        longitude: null,
        latitude: null,
      };
      this.stationDescList = [{
        value: ''
      }]
      this.wrokPlaceType = 1
      this.startSalaryRange = null
      this.endSalaryRange = null
      this.longitudeAndLatitude = null
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.getStationCount()
    },
    handleChangeFilterStation(arr) {
      this.queryParams.stationType = arr[2]
      console.log(arr, 'handleChangeFilterStation')
    },
    handleChangeStation(arr) {
      this.form.stationType = arr[2]
      console.log(arr, 'handleChangeStation')
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.stationArr = null
      this.queryParams.stationType = null
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleChangeIsHot(item) {
      item.isHot = item.hotBool ? 1 : 0
      updateStation(item).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.getList();
        this.getStationCount()
      });
    },
    handleChangeStatus(item) {
      item.status = item.statusBool ? 1 : 0
      updateStation(item).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.getList();
        this.getStationCount()
      });
    },
    // 选择工作地点
    handleChangePlace() {
      if (this.wrokPlaceType === 1) {
        this.form.stationAddr = ''
        this.longitudeAndLatitude = ''
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.dialogType = 'add'
      this.title = "添加公司岗位信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row, type = '') {
      this.reset();
      const id = row.id || this.ids
      this.dialogType = type
      getStation(id).then(response => {
        console.log(response, 'response')
        this.form = response.data;
        this.wrokPlaceType = this.form.wrokPlaceType
        this.longitudeAndLatitude = this.form.companyInfo.latitude + ',' + this.form.companyInfo.longitude
        this.startSalaryRange = this.form.salaryRange.split('-')[0]
        this.endSalaryRange = this.form.salaryRange.split('-')[1]
        const tempArr = this.form.stationSpecifics.split(',')
        this.stationDescList = tempArr.map(item => ({
          value: item
        }))
        this.open = true;
        if (type === 'examine') {
          this.title = "审核岗位";
        } else if (type === 'detail') {
          this.title = "查看岗位";
        } else {
          this.title = "修改岗位";
        }

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.transformParams()
          if (this.form.id != null) {
            updateStation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.getStationCount()
            });
          } else {
            addStation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.getStationCount()
            });
          }
        }
      });
    },
    // 审核岗位
    handlePass(status) {
      this.form.isExamine = status
      updateStation(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
        this.getStationCount()
      });
    },
    transformParams() {
      console.log(this.longitudeAndLatitude, 'this.longitudeAndLatitude')
      this.form.compId = this.companyId ? this.companyId : this.form.compId
      this.form.wrokPlaceType = this.wrokPlaceType
      this.form.salaryRange = this.startSalaryRange + '-' + this.endSalaryRange
      this.form.stationSpecifics = this.stationDescList.map(item => item.value).join(',')
      if (this.wrokPlaceType === 1) {
        // const compInfo = this.companyList.filter(item => item.id === this.form.compName)
        // if (compInfo?.length) {
        //   this.form.latitude = compInfo[0].latitude
        //   this.form.longitude = compInfo[0].latitude
        // }
        // this.form.stationAddr = compInfo[0].compAddr
      } else {
        this.form.latitude = this.longitudeAndLatitude.split(",")[0]
        this.form.longitude = this.longitudeAndLatitude.split(",")[1]
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除公司岗位信息编号为"' + ids + '"的数据项？').then(function () {
        return delStation(ids);
      }).then(() => {
        this.getList();
        this.getStationCount()
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 导入
    handleImport() {
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      const fileUrl = require('@/assets/xlsxTemplate/stationTemplate.xlsx')
      const link = document.createElement('a')
      link.href = fileUrl
      link.download = '招聘岗位管理-数据导入模板.xlsx'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (response.code === 200) {
        this.$modal.msgSuccess("导入成功");
        this.getList();
        this.getStationCount()
      } else {
        this.$modal.msgError("导入失败");
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      }
    },
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/station/export', {
        ...this.queryParams
      }, `station_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss">
.salaryRange .el-form-item__content {
  display: flex
}

.station-form .el-dialog__body {
  max-height: 700px;
  overflow-y: auto;
}
</style>
